package com.csmzxy.soft.comm;

public class overdraftAmount extends Account {
    private double maxOverdraftAmount;
    private double overdraftAmount;

    public overdraftAmount(String id,String pwd,double balance){
        this(id,pwd,balance,0);
        this.overdraftAmount=0;
    }
    public overdraftAmount(String id,String pwd,double balance,double maxOverdraftAmount){
        super(id,pwd,balance);
        this.maxOverdraftAmount=maxOverdraftAmount;
        this.overdraftAmount=0;
    }
    public double getMaxOverdraftAmount(){
        return maxOverdraftAmount;
    }
    public void setmaxOverdraftAmount(double maxOverdraftAmount){
        this.maxOverdraftAmount=maxOverdraftAmount;
    }
    public double getOverdraftAmount(){
        return overdraftAmount;
    }
    public boolean withdraw(double money){
        if(money<=balance){
            return super.withdraw(money);
        }
        if(balance+maxOverdraftAmount-overdraftAmount>=money){
            overdraftAmount+=money-balance;
            balance=0;
            return true;
        }
        return false;
    }
    public void deposit(double money){
        if(overdraftAmount==0){
            super.deposit(money);
        }else{
            if(money>=overdraftAmount){
                balance=money-overdraftAmount;
                overdraftAmount=0;
            }else{
                overdraftAmount-=money;
            }
        }
    }
}
